package org.bookie.mtest;


import java.util.List;

import org.apache.hivemind.Registry;
import org.apache.hivemind.impl.RegistryBuilder;
import org.bookie.model.Category;
import org.bookie.model.services.CategoryDAO;
import org.bookie.model.services.UserDAO;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
 * Module test of the Bookie-Model projec
 * 
 * @author zubairov
 *
 */
@Test
public class ModelIntegrationTest extends Assert {

	public void testRegistryStartup() throws Exception {
		RegistryBuilder.constructDefaultRegistry();
	}
	
	public void testDatabaseSchemaUpgrade() throws Exception {
		Registry registry = RegistryBuilder.constructDefaultRegistry();
		CategoryDAO dao = (CategoryDAO) registry.getService(CategoryDAO.class);
		List<Category> allCat = dao.findAll();
		assertTrue(allCat.isEmpty());
		dao.makePersistent(new Category("testCategory"));
		allCat = dao.findAll();
		assertFalse(allCat.isEmpty());
	}
	
	public void testUserDAO() throws Exception {
		Registry registry = RegistryBuilder.constructDefaultRegistry();
		UserDAO dao = (UserDAO) registry.getService(UserDAO.class);
		dao.findAll();
	}
}
